package com.appointment.web;

import java.text.SimpleDateFormat;
import java.util.Date;


public class PrintTimeFunction {
//	private final static SimpleDateFormat TIME_STAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
//    private final static SimpleDateFormat MY_DATE_FORMAT = new SimpleDateFormat("yyyy年MM月dd日");
	
	public static String getNiceDate(Object date) {
        if (null == date) return "";
        String dateString = date.toString();
        String result = null;
        SimpleDateFormat timeformat = new SimpleDateFormat(
                "yyyy-MM-dd");
        
        try {
           
        	//Date d = timeformat.parse((String) date);
			//date = TIME_STAMP_FORMAT.parse(dateString);
            long currentTime = new Date().getTime() - ((Date)date).getTime();
            int time = (int) (currentTime / 1000);
            if (time < 60) {
                result = "刚刚";
            } else if (time >= 60 && time < 3600) {
                result = time / 60 + "分钟前";
            } else if (time >= 3600 && time < 86400) {
                result = time / 3600 + "小时前";
            } else if (time >= 86400 && time < 864000) {
                result = time / 86400 + "天前";
            } else {
            	result = timeformat.format(date);
                //result = date.toString();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
